/*调用示例
*创建实例 
*containId是将弹出框作为其子节点的元素id,为空将默认添加到document.body
*popBoxId 是弹出层的Id，默认是popBox
* var popBox=new PopWindow(popWindowId,containId);
*popBox.open(htmlText); //htmlText是弹出框要显示的html片段字符串
*
*/
function PopWindow(popWindowId,containId){
	this.contain=document.getElementById(containId)||document.body;
	this.id=popWindowId||"PopWindow";
}
//获得视口大小
PopWindow.prototype.getViewport=function(){
	return {//IE混杂模式下，须用document.body.clientWidth
		width:document.documentElement.clientWidth||document.body.clientWidth,
		height:document.documentElement.clientHeight||document.body.clientHeight
	}
}
//获得页面大小
PopWindow.prototype.getPagesize=function(){
	return {
		width:Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth),
		height:Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)
	}
}
PopWindow.prototype.setOpacity=function(elem,level){
	elem.style.filter='alpha(opacity='+level+')';//IE滤镜的方法
	elem.style.opacity=level/100;   //W3C
}
PopWindow.prototype.setPos=function(pos){
	this.popBox.style.position=pos;
}
//显示弹出框位置
PopWindow.prototype.showBox=function(){
     //显示遮罩层
	this.pageSize=this.getPagesize();
	this.viewPort=this.getViewport();
	this.hidden.style.width=this.pageSize.width+"px";
	this.hidden.style.height=this.pageSize.height+"px";
	this.hidden.style.display="block";
	//设置在屏幕中的位置
	var that=this;
	this.popBox.style.display="block";
	this.popBox.style.left=(this.viewPort.width-this.popBox.offsetWidth)/2+"px";
	var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
	this.popBox.style.top=(this.viewPort.height-this.popBox.offsetHeight)/2+scrollTop+"px";
}
PopWindow.prototype.close=function(){
		this.popBox.style.display="none";
		this.hidden.style.display="none";
}
PopWindow.prototype.setHiddenColor=function(color){
	if(this.hidden){
		this.hidden.style.backgroundColor=color;
	}
}
/*
*@param opacity 遮罩透明度 
*/
PopWindow.prototype.init=function(opacity){
		var opacity=opacity||20;
		if(this.initFlag!=1){
			this.initFlag=1;
		}else{
			return false;;
		}
	//将隐藏层添加到文档中
	//创建半透明的遮罩层,并设置样式
		this.hidden=document.createElement("div");
		this.hidden.id="hidden";
		this.hidden.style.backgroundColor="black"
		this.hidden.style.position="absolute";
		this.hidden.style.left="0px";
		this.hidden.style.top="0px";
		this.hidden.style.zIndex=999;
		this.setOpacity(this.hidden,opacity);
		document.body.appendChild(this.hidden);
		this.hidden.style.display="none";
	//添加弹出框，并设定基本样式
		this.popBox=document.createElement("div");
		this.popBox.id=this.id;
		this.popBox.style.position="absolute";
		this.popBox.style.display="none";
		this.popBox.style.zIndex=1000;
		this.popBox.style.backgroundColor="white";
		this.contain.appendChild(this.popBox);
}
//打开一个新的窗口显示htmlText片段内容
PopWindow.prototype.open=function(htmlText){
		this.init();
		this.popBox.innerHTML=htmlText;
		this.showBox();
}